<template>
  <div class="goods-list">
    <div class="goods-item" v-for="(item,index) in list" :key="index" @click="shangpingyemian(item.name)">
      <img v-lazy="poot + 'miaozishangchengFile/commodity/'+item.name+'/'+item.name+'.jpg'" />
     
      <h1 class="title">{{item.name}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">{{item.price.split(",")[0]}}</span>
          <span class="old">{{item.oldprice}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余{{item.stock}}</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";
export default {
    props: ["shop"],
  data() {
    return {
      list: [],
    };
  },
  methods: {
    ...mapMutations(["xg"]),
    ...mapMutations(["userxg"]),
    ...mapMutations(["yxxg"]),
    shangpingyemian( name) {
      this.$router.push("shangpinxiangqing"+"/"+name);
      this.xg(true);
    },
    chushihua() {
      this.$http
        .get(this.poot + this.shop)
        .then(response => {
          console.log(response.data);
          this.list = response.data;
        })
        .catch(function(error) {
          console.log(error);
          alert("获取数据失败");
        });
    }
  },
  computed: {
    ...mapState(["poot"]),
    ...mapState(["yx"]),
    ...mapState(["zhuantai"])
  },
  mounted() {
    this.chushihua();
  }
};
</script>
<style scoped>
.price {
  text-align: left;
}
.goods-list {
  display: flex;
  flex-wrap: wrap;
  margin: 7px;
  justify-content: space-around;
  margin-bottom: 50px;
}
.goods-item {
  width: 49%;
  border: 1px solid#ccc;
  box-shadow: 0 0 8px #ccc;
  margin: 3px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* 在弹性盒对象的 <div> 元素中的各项周围留有空白 */
  min-height: 293px;
  background-color: #eee;
 
}
img {
  width: 100%;
  height: 75%;
}
.title {
  font-size: 14px;
  text-align: left;
}
.info {
  background-color: #eee;
}

.now {
  color: red;
  font-size: 16px;
  font-weight: bold;
}
.old {
  text-decoration: line-through;
  font-size: 10px;
}
.sell {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
p {
  margin: 0;
}
</style>